import numpy as np
import random

def getRand():
    return random.randint(0,10) / 10

def buildAl():
    al = []
    for _ in range(3):
        inAl = []
        for _ in range(3):
            inAl.append(getRand())
        al.append(inAl)
    return al

al = buildAl()
a = np.array(al)

def guiyi(l):
    s = np.sum(l)
    for i in range(len(l)):
        l[i] /= s
    return l

# 归一化所有行
for i in range(3):
    a[i] = guiyi(a[i])

print(a)

def set0(i, j):
    a[i, j] = 0
    while True:
        print('归一化当前行')
        a[i] = guiyi(a[i])
        print(a)
        print('归一化当前列')
        a[:, j] = guiyi(a[:, j])
        print(a)
        print('归一化其它行')
        for i_i in range(3):
            if i_i != i:
                a[i_i] = guiyi(a[i_i])
                print(a)
        print('归一化其它列')
        for j_i in range(3):
            if j_i != j:
                print('归一化', j_i, '列')
                a[:, j_i] = guiyi(a[:, j_i])
                print(a)

set0(1,1)